#ifndef BASE_H
#define BASE_H

/*
 *  Format of the current_step:
 *    - three low bit is for first index;
 *    - three next bits is for second index;
 *    - 7th bit indicates X or O set contains;
 *
 *  examples:
 *
 *  0 0 0 0 0 0 0 0 - O at [0][0]
 *  0 0 0 0 0 0 0 1 - O at [0][1]
 *  0 0 1 0 0 0 0 1 - O at [3][1]
 *  .............................
 *  1 0 1 0 0 0 0 1 - X at [3][1]
 *  1 0 1 0 0 0 1 1 - isn't valid
 *  1 1 1 1 1 1 1 1 - error occured or end of game.
 *
 *  Return value:
 *   If step is valid, returns array of 3 chars:
 *   [0] - X/O (0xFF - end of game)
 *   [1] - X
 *   [2] - y
 *   otherwise return null.
 */

int decode_step (unsigned char current_step, unsigned char * result);

/*
 *  Format of encoding the same as decode_step have.
 *
 *  current_step must have the folowing format:
 *    [0] - X/O or end of game 
 *    [1] - X
 *    [2] - y
 *    where x and y must be less than 0x9 and [0] may take one
 *    of the following values:
 *      [0] == 0xFF - end of game or error.
 *
 *  Return value:
 *   if current_step is null or if (current_step[0] > 1 && current_step[0] != 0xFF) or 
 *   if current_step[1] or current_step[2] > 3 return 0b01000000,
 *   otherwise returns encapsulated step.
 */

int encode_step (unsigned char * current_step, unsigned char * res);

int send_to (int fifo_fd, unsigned char step);

int receive_from (int fifo_fd, unsigned char * current_step);

#endif // BASE_H
